package com.zut.controller;
import com.zut.entity.OrderInfo;
import com.zut.enums.OrderStatus;
import com.zut.service.OrderInfoService;
import com.zut.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin
@Api(tags = "订单管理")
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;
    // 获取所有的订单信息
    @GetMapping("/list")
    public R list() {
        List<OrderInfo> list = orderInfoService.listOrderByCreateTimeDesc();
        System.out.println("来了");
        return R.ok().data("list",list);
    }

    // 查询本地订单
    @GetMapping("/query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo) {
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        System.out.println("支付状态 = " + orderStatus);
        if(OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok().setCode(0).setMessage("支付成功！！！");
        }
        return R.ok().setCode(100).setMessage("支付中！！！");
    }
}
